# encoding=utf-8
# author:梁子龙
# -*- coding: utf-8 -*-
# author: liangzilong
from comment.utils.Serializer import BaseListSerializer, BaseSerializer


class UserInfoSerializer(BaseSerializer):
    """用户信息序列化"""

    def to_dict(self):
        obj = self.data
        ls=[]
        return {
            'id': obj.id,
            'username': obj.username,
            'nickName': obj.nick_name,
            "role": "管理员" if obj.role == 1 else "普通用户"
        }
class AllUserInfoSerializer(BaseListSerializer):
    """用户信息序列化"""

    def to_dict(self):
        lst = []

        for obj in self.data_list:
            role=[]
            for i in obj.role:
                print(i.name)
                role.append(i.name)
            lst.append(
                {
                    'id': obj.id,
                    "name": obj.username,
                    "role": role
                }
            )
        return lst

class OrderListSerializer(BaseListSerializer):
    """
    银行卡列表数据 序列化的类
    """

    def to_dict(self):
        lst = []
        for order in self.data_list:
            lst.append(
                {
                    'orderId': order.orderId,
                    'orderName': order.orderName
                }
            )
        return lst


class RoleInfoSerializer(BaseListSerializer):
    """用户信息序列化"""

    def to_dict(self):
        lst = []
        for obj in self.data_list:
            lst.append(
                {
                    'id': obj.id,
                    "role": obj.name
                }
            )
        return lst


class PermissionSerializer(BaseListSerializer):
    """用户信息序列化"""

    def to_dict(self):
        lst = []
        for obj in self.data_list:
            lst.append(
                {
                    'id': obj.id,
                    "permission": obj.name,
                    "method": obj.method
                }
            )
        return lst

class ProjectSerializer(BaseListSerializer):
    """用户信息序列化"""

    def to_dict(self):
        lst = []
        for obj in self.data_list:
            lst.append(
                {
                    'id': obj.id,
                    "project": obj.name,
                    "url": obj.url
                }
            )
        return lst